﻿using DBServer.Selenium.Extenium.Exception;
using DBServer.Selenium.Extenium.Path;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class FieldSetFixture : ExtComponentFixture
    {
        private readonly IPath _path;

        public FieldSetFixture(ISelenium driver, IPath path)
            : base(driver, path)
        {
            _path = path;
        }

        public FieldSetFixture Expand()
        {
            var command = _path + ".expand();";
            SafeExec(command);
            return this;
        }

        public FieldSetFixture Collapse()
        {
            var command = _path + ".collapse();";
            SafeExec(command);
            return this;
        }

        public FieldSetFixture RequireCollapsed()
        {
            var command = _path + ".collapsed;";
            var selected = bool.Parse(SafeExec(command));
            if (!selected)
            {
                throw new ExteniumException("FieldSet was not collapsed");
            }
            return this;
        }

        public void RequireExpanded()
        {
            var command = _path + ".collapsed;";
            var selected = bool.Parse(SafeExec(command));
            if (selected)
            {
                throw new ExteniumException("FieldSet was not expanded");
            }
        }

    }
}